function [pscale] = WATSON_mark4(WATSON_in_path, WATSON_out_path, WATSON_name, WATSON_out_filetype, mcount, alpha, wy_azimuth, wat_z_dim)

%Program that marks a WATSON image on a surface drilled with Mars 2020 Coring Drill
%Marked directions:
%   Core y-axis projected on to image plane (Cy)
%   WATSON y- and z-axes  (Wy and Wz)
%   Projection of Martian north projected on to image plane (


figure
%disp('Pick a Watson rmg file to import and annotate: ')
%[filename,filepath]=uigetfile({'*.png'},'Select and image');

image=imread([WATSON_in_path, WATSON_name,'.png']);
imshow(image)
imx=length(image(1,:,:));
imy=length(image(:,1,:));
hold on
quiver(imx/2,imy/2,imy/5,0,0,'w','LineWidth',9,'MaxHeadSize',.5)
hold on
quiver(imx/2,imy/2,0,-1*imy/5,0,'w','LineWidth',9,'MaxHeadSize',.5)

text(imx/2+imy/4,imy/2,'\itW_z','Color','w','FontSize',36)
text(imx/2,imy/2 - imy/4,'\itW_y','Color','w','FontSize',36)

wy_image=[0,1,0].';
 rot_z=vertcat([cosd(-1*alpha) -1*sind(-1*alpha) 0],[sind(-1*alpha) cosd(-1*alpha) 0],[0 0 1]);
%rot_z=vertcat([cosd(-1*northcheckim) -1*sind(-1*northcheckim) 0],[sind(-1*northcheckim) cosd(-1*northcheckim) 0],[0 0 1]);

cy_image=rot_z*wy_image;

quiver(imx/2,imy/2,(imy/4)*cy_image(1),-1*(imy/4)*cy_image(2),0,'w','LineWidth',9,'MaxHeadSize',.5)
text(imx/2 + ((imy/3)*cy_image(1)),imy/2 + (-1*(imy/3)*cy_image(2)),'\itC_y','Color','w','FontSize',36)


%%% Plot Martian North (Projection onto Wy-Wz Plane)
    % Get normal to plane

rot_z=vertcat([cosd(-1*wy_azimuth) -1*sind(-1*wy_azimuth) 0],[sind(-1*wy_azimuth) cosd(-1*wy_azimuth) 0],[0 0 1]); %build a rotation matrix that rotates any vector by wy_azimuth [deg CW]
mars_north=rot_z*wy_image;

quiver(imx/2,imy/2,(imy/4)*mars_north(1),-1*(imy/4)*mars_north(2),0,'w','LineWidth',9,'MaxHeadSize',.5)
text(imx/2 + ((imy/3.5)*mars_north(1)),imy/2 + (-1*(imy/3.5)*mars_north(2)),'Martian North','Color','w','FontSize',36)

%%% draw a arc for a given angle 
rad=100;
angs=1:1:alpha;
xc=length(image(1,:,:))/2+rad*cosd(angs-90);
yc=length(image(:,1,:))/2+rad*sind(angs-90);   
plot(xc,yc,'w','LineWidth',9)
alptext=['\it\alpha = \rm',int2str(alpha),char(176)];

if alpha<90
    if rem(length(angs),2)==0
        %text(xc(length(xc)/2)+150,yc(length(yc)/2)-150,alptext,'Color','w','FontSize',24)
    else
        %text(xc(.5+length(xc)/2)+150,yc(.5+length(yc)/2)-150,alptext,'Color','w','FontSize',24)
    end
elseif alpha>90 && alpha<180
    if rem(length(angs),2)==0
        %text(xc(length(xc)/2)-200,yc(length(yc)/2)+150,alptext,'Color','w','FontSize',24)
    else
        %text(xc(.5+length(xc)/2)+150,yc(.5+length(yc)/2)-150,alptext,'Color','w','FontSize',24)
    end
elseif alpha>180 && alpha<270
    if rem(length(angs),2)==0
        %text(xc(length(xc)/2)-300,yc(length(yc)/2)+150,alptext,'Color','w','FontSize',24)
    else
        %text(xc(.5+length(xc)/2)-150,yc(.5+length(yc)/2)+150,alptext,'Color','w','FontSize',24)
    end
else
    if rem(length(angs),2)==0
        %text(xc(length(xc)/2)-150,yc(length(yc)/2)-150,alptext,'Color','w','FontSize',24)
    else
        %text(xc(.5+length(xc)/2)-150,yc(.5+length(yc)/2)-150,alptext,'Color','w','FontSize',24)
    end
end

%%% Calculate Motor Count and Plot Scale Bar
%From Excel Sheet
wdist=1/((1091060/(mcount))+(-332.921)+(0.0382592*(mcount))+(-0.00000196922*((mcount^2))+(0.0000000000384562*((mcount^3))))); %working distance (cm) from cell C11
pscale=6.528+(3.7261*wdist)+(-0.0057102*(wdist^2))+(0.000040576*(wdist^3))+(-0.000000083282*(wdist^4)); %pixel scale (microns per pixels) from cell E11
frame_width=pscale* wat_z_dim/10000; %pixel scale (um/pix) * # pix *conversion of um to cm. Product is frame width in cm

cm_length=(imx/frame_width); %number of pixels equal to 1 cm in output image

plot([150 150+(cm_length)],[imy-100 imy-100],'w','LineWidth',20);
text(30+cm_length/2,imy-200,'1 cm','Color','w','FontSize',36);


exportgraphics(gcf,[WATSON_out_path, WATSON_name,'_Orientation_Annotated.', WATSON_out_filetype])
%close all

end


